#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	long MAX;
	cin >> MAX;
	string an,tmp;
	long mch;
	vector<long> mchnum;
	vector<string> ans;
	for (long i = 0;i < MAX;i++)
	{
		cin >> an >> mch >> tmp;
		an += ' ';
		an += tmp;
		mchnum.push_back(mch);
		ans.push_back(an);
	}
	long flag,tp;
	vector<int> num;
	cin >> flag;
	for (long i = 0;i < flag;i++)
	{
		cin >> tp;
		num.push_back(tp);
	}
	for (long i = 0;i < flag;i++)
	{
		for (long j = 0;j < mchnum.size();j++)
		{
			if (num[i] == mchnum[j])
			{
				cout << ans[j] << endl;
				break;
			}
		}
	}
	return 0;
}
